package cn.com.xinjinfu.pdoulcProduct.manager;

import static android.view.Gravity.BOTTOM;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.widget.Toast;

import cn.com.xinjinfu.pdoulcProduct.R;
import cn.com.xinjinfu.pdoulcProduct.view.LoadingDialog;

public class ToastManager {
    private static LoadingDialog dialog;
//    public Dialog dialog;
    public static void show(Activity context, Object text) {
        showShort(context, text + "");
//		show(context, text, 0);
    }

    //屏幕最下方的提示
    public static void show(Activity context, Object text, int duration) {
        if (text instanceof String) {
            AppMsg appMsg = AppMsg.makeText(context, text.toString(),
                    AppMsg.STYLE_TRAN_INFO);
//            appMsg.setParent(R.id.top);
            appMsg.setLayoutGravity(BOTTOM);
            appMsg.setDuration(1000);
            appMsg.show();
            return;
        }
        if (text instanceof Integer) {
            AppMsg appMsg = AppMsg.makeText(context, (Integer) text,
                    AppMsg.STYLE_TRAN_INFO);
//            appMsg.setParent(R.id.top);
            appMsg.setLayoutGravity(BOTTOM);
            appMsg.setDuration(1000);
            appMsg.show();
            return;
        }

    }
    /**
     * 系统toast,三星如果不开启权限看不到
     */
    public static void showToastShort(Context context,String s){
        Toast.makeText(context,s,Toast.LENGTH_SHORT).show();
    }

    /**
     * 仿系统toast
     */
    public static void showShort(Context context,String msg){
        dialog = new LoadingDialog(context,msg);
        dialog.setCancelable(true);
        dialog.show();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1200);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        }).start();
    }

    /**
     * 显示维护Dialog
     * @param context
     * @param msg
     */
    @SuppressLint("NewApi")
    public static void showNetDialog(Context context, Object msg){
        Builder build = new AlertDialog.Builder(context,R.style.netLoadingDialog);
        build.setTitle("消息提示");
        if(msg instanceof String){
            build.setMessage(msg.toString());
        }else if (msg instanceof Integer) {
            build.setMessage(Integer.parseInt(msg.toString()));
        }
        build.setPositiveButton("确定", null);
        build.create().show();
    }
}
